package landian.com.myapplication11;

import android.content.Intent;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.widget.LinearLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import landian.com.module_base.BaseActivity;
import landian.com.module_base.BasePresenter;

/**
 * Created by Administrator on 2019-03-05.
 */

public class TextFragmentActivity extends BaseActivity implements ViewPager.OnPageChangeListener {
    @BindView(R.id.tabL)
    TabLayout mTabL;
    @BindView(R.id.viewpager)
    ViewPager mViewpager;

    private TextFragmentPagerAdapter mTextFragmentPagerAdapter;
    private List<Fragment> mFragmentList = new ArrayList<>();

    @Override
    protected int getContentView() {
        return R.layout.fragment_text_fragment;
    }

    @Override
    protected void initView(Intent intent) {
        for (String title : TextFragmentPagerAdapter.TITLES) {
            mTabL.addTab(mTabL.newTab());
            mFragmentList.add(new TextFragment());



        }
        //设置分割线
        LinearLayout linearLayout = (LinearLayout) mTabL.getChildAt(0);
        linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
        linearLayout.setDividerDrawable(ContextCompat.getDrawable(this,
                R.drawable.divider)); //设置分割线的样式
        linearLayout.setDividerPadding(30); //设置分割线间隔

        mTextFragmentPagerAdapter = new TextFragmentPagerAdapter(getSupportFragmentManager(), mFragmentList);
        mViewpager.setAdapter(mTextFragmentPagerAdapter);
        mTabL.setupWithViewPager(mViewpager);
    }

    @Override
    protected BasePresenter initPresenter() {
        return null;
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        mViewpager.setCurrentItem(position);
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
